package com.fish.web.passport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.fish.common.constant.Constant;
import com.fish.common.constant.QueryPage;
import com.fish.common.web.BaseAction;
import com.fish.passport.po.PassDevice;
import com.fish.passport.po.PassProvider;
import com.fish.product.po.PerformTarget;
import com.fish.service.passport.PassDeviceService;
import com.fish.service.passport.PassProviderService;
import com.fish.service.passport.PerformTargetService;
/**
 * 设备管理
 * @author clj
 *
 */
public class DeviceAction extends BaseAction {
	private static final long serialVersionUID = 1247295319708066072L;
	private PassDevice device = new PassDevice();
	private PassProviderService passProviderService;
	private PerformTargetService performTargetService;
	private PassDeviceService passDeviceService;
	private List<PassProvider> providerList;
	private List<PassDevice> deviceList = new ArrayList<PassDevice>();
	private List<PerformTarget> performTargetList = new ArrayList<PerformTarget>();
	private QueryPage queryPage = new QueryPage();

	public String goToDeviceList(){
		 return this.deviceList();
	}
	public String edit() {
		if (StringUtils.isBlank(this.device.getDeviceId()) ){
			device.setDeviceId(getNewUUID());
			this.passDeviceService.addPaasDevice(device);
		} else {
			this.passDeviceService.updatePaasDevice(device);
		}
		return SUCCESS;
	}

	public String delete() {
		if (this.device.getDeviceId()!=null) {
			this.passDeviceService.delDeviceByDeviceId(this.device.getDeviceId());
		}
		return deviceList();
	}

	public String goToEdit() {
		this.providerList=this.passProviderService.queryPassProviders(null);
		if (this.device != null) {
			this.device= this.passDeviceService.getPaasDeviceByDeviceId(this.device.getDeviceId());
		}
		return SUCCESS;
	}

	public String deviceList() {
		this.providerList=this.passProviderService.queryPassProviders(null);
		this.performTargetList = performTargetService.queryPerformTargetByObject(null,null);
		Long count = passDeviceService.queryPaasDeviceCountByObject(device);
		if(count > 0){
			queryPage = new QueryPage(count, Constant.DEFAULT_PAGE_SIZE, queryPage.getCurPage());
		}		
		deviceList = passDeviceService.queryPaasDeviceByObject(device,queryPage);
		return SUCCESS;		
	}

	public PassDevice getDevice() {
		return device;
	}

	public void setDevice(PassDevice device) {
		this.device = device;
	}

	public PassProviderService getPassProviderService() {
		return passProviderService;
	}

	public void setPassProviderService(PassProviderService passProviderService) {
		this.passProviderService = passProviderService;
	}

	public PassDeviceService getPassDeviceService() {
		return passDeviceService;
	}

	public void setPassDeviceService(PassDeviceService passDeviceService) {
		this.passDeviceService = passDeviceService;
	}

	public List<PassProvider> getProviderList() {
		return providerList;
	}

	public void setProviderList(List<PassProvider> providerList) {
		this.providerList = providerList;
	}

	public List<PassDevice> getDeviceList() {
		return deviceList;
	}

	public void setDeviceList(List<PassDevice> deviceList) {
		this.deviceList = deviceList;
	}
	public QueryPage getQueryPage() {
		return queryPage;
	}
	public void setQueryPage(QueryPage queryPage) {
		this.queryPage = queryPage;
	}
	public List<PerformTarget> getPerformTargetList() {
		return performTargetList;
	}
	public void setPerformTargetList(List<PerformTarget> performTargetList) {
		this.performTargetList = performTargetList;
	}
	public void setPerformTargetService(PerformTargetService performTargetService) {
		this.performTargetService = performTargetService;
	}
	
	
}
